/***********************************************************************
 * Module:  Album.java
 * Author:  Voja
 * Purpose: Defines the Class Album
 ***********************************************************************/

package model.entity;

import static javax.persistence.FetchType.LAZY;
import static javax.persistence.GenerationType.IDENTITY;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;

@Entity
@Table(name = "album")
public class Album implements Serializable {

	private static final long serialVersionUID = 4343010815339384114L;

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "album_id", unique = true, nullable = false)
    private Integer id;
	
	@Column(name = "album_title", unique = false, nullable = true)
    private String title;
	
	@Column(name = "album_description", unique = false, nullable = true)
    private String description;
	
	@Column(name = "album_pub", unique = false, nullable = true)
    private Boolean pub;
   
	@Column(name = "album_favorite", unique = false, nullable = true)
    private Boolean favorite;
	
	@ManyToMany(cascade={CascadeType.ALL}, fetch=FetchType.EAGER,mappedBy = "albums")
    private Set<Photo> photos=new HashSet<Photo>();
	
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name = "user_id", referencedColumnName = "user_id", nullable = false)
    private User user;

	public Album(){
		favorite=false;
	}
	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Boolean getPub() {
		return pub;
	}

	public void setPub(Boolean pub) {
		this.pub = pub;
	}
	
	public Boolean getFavorite() {
		return favorite;
	}

	public void setFavorite(Boolean favorite) {
		this.favorite = favorite;
	}

	public Set<Photo> getPhotos() {
		return photos;
	}

	public void setPhotos(Set<Photo> photos) {
		this.photos = photos;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	@Override
	public String toString() {
		return "Album [id=" + id + "]";
	}
	
	@Override
	public boolean equals(Object obj) {
		if(!(obj instanceof Album))
			return false;
		return ((Album)obj).getId().intValue()==getId().intValue();
	}
}